package com.zou.demo.bootstrapcurd.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.zou.demo.bootstrapcurd.model.LoginUser;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author: 邹祥发
 * @date: 2021/8/13 09:50
 */
public interface LoginUserMapper extends BaseMapper<LoginUser> {
    @Select("select loginName from login_user where loginName = #{loginName}")
    String selectName(String loginName);

    @Select("select loginPwd from login_user where loginName = #{loginName}")
    String selectPwdByName(String loginName);

    @Insert("INSERT INTO `login_user` (loginName,loginPwd) VALUES (#{loginName},#{loginPwd})")
    void registerUser(String loginName, String loginPwd);

    @Select("select * from login_user")
    List<LoginUser> selectLoginUser();

    @Select("select permission from login_user where loginName = #{loginName}")
    Integer selectPermission(String loginName);

    @Update("UPDATE login_user SET loginName=#{loginName},loginPwd=#{loginPwd},permission=#{permission} WHERE id = #{id}")
    void updateUser(LoginUser loginUser);

    @Select("select * from login_user where id = #{id}")
    LoginUser selectUserById(Integer id) throws Exception;

    @Delete("delete from login_user where id=#{id}")
    void del(Integer id) throws Exception;

    @Insert("insert into login_user (loginName,loginPwd,permission) VALUES (#{loginName},#{loginPwd},#{permission})")
    void insertUser(LoginUser loginUser) throws Exception;

    @Select("select * from login_user where loginName = #{loginName}")
    LoginUser selectUserByName(String loginName) throws Exception;

    @Update("UPDATE login_user SET qq=#{qq},wechat=#{wechat},blog=#{blog},github=#{github},hobby=#{hobby} WHERE loginName=#{loginName}")
    void updateUserInfo(LoginUser loginUser);

    @Update("UPDATE login_user SET loginPwd=#{loginPwd} WHERE loginName=#{loginName}")
    void editPwd(String loginPwd, String loginName);
}
